(function( $ ){

  var methods = {
     init : function( options ) {

       return this.each(function(){
         var $this = $(this);
         if ($this.val() == '') $this.val(0);
         var btn_1 = $("<button />").html('<').click(function(){
            var $txt = $(this).next(),
                preValue = parseInt($txt.val()) - 1;
            if (isNaN(preValue)) preValue = 0;
            if (preValue >= 0) $txt.val(preValue);
            
         });
         var btn_2 = $("<button />").html('>').click(function(){
            var $txt = $(this).prev(),
                nextValue = parseInt($txt.val()) + 1;
            if (isNaN(nextValue)) nextValue = 1;
            $txt.val(nextValue);
            
         });
         $this.attr({"maxlength":"2", "size":"1"}).before(btn_1).after(btn_2);
         if (false) {
             $this.keydown(function(event) {
                if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 ||
                 event.keyCode == 27 || event.keyCode == 13 || 
                    (event.keyCode == 65 && event.ctrlKey === true) || 
                    (event.keyCode >= 35 && event.keyCode <= 39)) {
                         return;
                }
                else {
                    if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) 
                    && (event.keyCode < 96 || event.keyCode > 105 )) {
                        event.preventDefault(); 
                    }   
                }
              });
         } else {
            $this.attr({"readonly":true});
         }
       });
     }
  };

  $.fn.incremental = function( method ) {
    
    if ( methods[method] ) {
      return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
    } else {
      $.error( 'Method ' +  method + ' does not exist on jQuery.incremental' );
    }    
  
  };

})( jQuery );